Microcontrollers (MCUs) are small, self-contained computers comprising a processing element, a program store, “scratch pad” memory and a number if input/output (I/O) pins. MCUs are very widely used in electronic products of all kinds, including computer peripherals (eg mice, keyboards, disk drives) consumer electronics (eg MP3 players, telephones, TV sets) and office equipment (eg photocopiers, fax machines)
Designers of microcontroller-based electronic devices frequently find that they need more I/O pins than their preferred microcontroller provides. Generally, the more input/output (I/O) pins an microcontroller has, the more it costs, and many of the lowest cost microcontroller are only offered in small packages with small numbers of I/O pins (for example up to sixteen I/O pins). In many microcontroller-based designs, the majority of the microcontroller I/O pins are used for reading the state of buttons, and for controlling light emitting diodes (LEDS). In one example application, there may be sixteen buttons and four LEDS. Using one I/O pin to read each button or control each LED would require twenty I/O pins. One conventional solution is to connect LEDS and buttons in a matrix, as shown in FIG. 1, in order to reduce the number of I/O pins.
FIG. 1 illustrates a conventional matrix of light emitting diodes and buttons comprised of four rows and five columns. Each of the rows and columns are associated with an I/O pin, such that there are a total of nine I/O pins. Four buttons are shown in each of the columns, COL 0, COL 1, COL 2 and COL 3, for a total of sixteen buttons. Four LEDS are shown in COL 4. A button 5 is shown connecting COL 1 with ROW 3, whereas an LED is shown connecting COL 4 with ROW 3.
In the conventional solution, the buttons are read by driving each row low (0V) in turn, and then reading the state of each column pin with a pull up resistor (not shown), COL 4 would be kept low during scanning to keep the scanning process from inadvertently lighting the LEDS. For example, to read button 5, ROW 3 is driven low and the COL 1 voltage is read with a pull up resistor.
The diodes are required in order to allow correct reading of all buttons with any combination of buttons to be pressed (otherwise “phantom keys” may be detected with certain combinations). The buttons are typically scanned periodically (e.g. every 100 ms) and scanning is generally fast (e.g. taking a total of 100 us). The remainder of the time, COL 4 is driven high, and the LEDS illuminated by driving the corresponding row pins low. In this conventional example the number of I/O pins required is reduced from twenty to nine by using this conventional method, at the cost of sixteen diodes. As diodes may cost as little as $0.001 each (one tenth of a US cent), this is often an acceptable cost to pay for the reduction in the number of I/O pins required.
FIG. 1A shows a single element of the conventional control matrix of FIG. 1. The button 5 connecting COL 1 with ROW 3 is shown as being connected in series with a diode 13. The cathode 9 of the diode 13 is shown connected to the button 5, whereas the anode 7 of the diode 13 is shown connected to COL 1. COL 1 and ROW 3 are each shown as including an I/O pin.
Disadvantages of conventional solution includes that it requires many I/O pins to read many buttons, and requires many I/O pins to control many LEDS, making it expensive and requiring the use of bigger microcontrollers.
The present invention addresses these and other problems associated with the prior art.